import QtQuick 2.0
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1
import QtGraphicalEffects 1.0

import "../common"
import "../../js/util.js" as Util
import "../../js/UI.js" as Style

import com.gocampus 1.0

Page {
    id: personpage
    property var finishedcallback
    property Component component: null
    property var m_objects: new Array
    signal subpageSignal(var code,var data)
    onSubpageSignal: {
        Util.popView(m_objects)
    }

    Component.onCompleted: {
        username.text = DatabaseEngine.persondata.name
        usremajor.text = DatabaseEngine.persondata.major
    }

    Flickable{
        id: flick
        anchors{
            top: parent.top
            left: parent.left
            right: parent.right
        }
        width: parent.width
        height: parent.height
        contentHeight: column.childrenRect.height
        clip: true
        Column{
            id: column
            width: parent.width
            height: m_lineValue*9
            Item{
                width: parent.width
                height: width*0.45
                Image{
                    anchors.fill: parent
                    source: "qrc:/image/personpage/bg-wo.jpg"
                }

                Item{
                    width: parent.width
                    height: m_lineValue*1.65
                    anchors.bottom: parent.bottom
                    anchors.bottomMargin: m_lineValue*0.5
                    HeadImage{
                        id: image
                        width: height
                        height: parent.height
                        anchors{
                            verticalCenter: parent.verticalCenter
                            left: parent.left
                            leftMargin: m_lineValue*0.5
                        }
                        isCallImage: true
                        m_source: "qrc:/image/personpage/headimage.jpg"
                    }
                    AText{
                        id: username
                        anchors.left: image.right
                        anchors.leftMargin: m_lineValue*0.2
                        anchors.top: parent.top
                        anchors.topMargin: (image.height - username.contentHeight*2)/3
                        width: m_root_id.width - m_lineValue*1.6
                        elide: Text.ElideRight
                        wrapMode: Text.NoWrap
                        font.pointSize: 20
                        color: "#ffffff"
//                        text: DatabaseEngine.persondata.name
//                        text: "毕业设计"
                    }
                    AText{
                        id: usremajor
                        anchors.left: image.right
                        anchors.leftMargin: 0.2*m_lineValue
                        anchors.top: username.bottom
                        anchors.topMargin: 0.2*m_lineValue
                        width: m_root_id.width - m_lineValue*1.6
                        elide: Text.ElideRight
                        wrapMode: Text.NoWrap
                        font.pointSize: 16
                        color: "#ffffff"
//                        text: DatabaseEngine.persondata.major
//                        text: "计算机科学与技术"
                    }
                }
            }
            Item{
                width: parent.width
                height: childrenRect.height
                BaseLine {
                    id: dataline
                    height:m_lineValue
                    anchors.top: parent.top
                    Image {
                        id: selfdata
                        anchors.left: parent.left
                        anchors.leftMargin: Util.leftMargin +(m_lineValue*1.5 - m_lineValue*1.5*0.7)/2
                        anchors.verticalCenter: parent.verticalCenter
                        sourceSize: Qt.size(m_lineValue*0.3,m_lineValue*0.3)
                        source: "qrc:/image/personpage/selfdata.png"
                    }
                    AText {
                        anchors.left: selfdata.right
                        anchors.leftMargin: m_lineValue*0.2
                        anchors.verticalCenter: parent.verticalCenter
                        text: qsTr("个人资料")
                        font.pointSize: Style.fontlittlcontent
                        color:Style.fonttilteColor
                    }
                    Image {
                        anchors.right: parent.right
                        anchors.rightMargin: m_lineValue*0.2
                        anchors.verticalCenter: parent.verticalCenter
                        sourceSize: Qt.size(m_lineValue*0.3,m_lineValue*0.3)
                        source: "qrc:/image/arrow.png"
                    }

                    onMouseclickSignal: {
                        Util.pushView(component,m_objects,"qrc:/qml/form/personpage/PersonInfo.qml",m_root_id,{})
                    }
                    SplitLine {
                        anchors {
                            bottom: parent.bottom
                            left: parent.left
                            leftMargin: m_lineValue*0.3
                            right: parent.right;
                        }
                    }
                }
                BaseLine {
                    id: changeline
                    height:m_lineValue
                    anchors.top: dataline.bottom
                    Image {
                        id: changepassword
                        anchors.left: parent.left
                        anchors.leftMargin: Util.leftMargin +(m_lineValue*1.5 - m_lineValue*1.5*0.7)/2
                        anchors.verticalCenter: parent.verticalCenter
                        sourceSize: Qt.size(m_lineValue*0.3,m_lineValue*0.3)
                        source: "qrc:/image/personpage/wo_password.png"
                    }
                    AText {
                        anchors.left: changepassword.right
                        anchors.leftMargin: m_lineValue*0.2
                        anchors.verticalCenter: parent.verticalCenter
                        text: qsTr("修改密码")
                        font.pointSize: Style.fontlittlcontent
                        color:Style.fonttilteColor
                    }
                    Image {
                        anchors.right: parent.right
                        anchors.rightMargin: m_lineValue*0.2
                        anchors.verticalCenter: parent.verticalCenter
                        sourceSize: Qt.size(m_lineValue*0.3,m_lineValue*0.3)
                        source: "qrc:/image/arrow.png"
                    }

                    onMouseclickSignal: {
                        Util.pushView(component,m_objects,"qrc:/qml/form/personpage/ChangePasswdPage.qml",m_root_id,{})
                    }
                    SplitLine {
                        anchors {
                            bottom: parent.bottom
                            left: parent.left
                            leftMargin: m_lineValue*0.3
                            right: parent.right;
                        }
                    }
                }
                BaseLine{
                    id: comproblem
                    anchors.top: changeline.bottom
                    height:m_lineValue
                    Image {
                        id: question
                        anchors.left: parent.left
                        anchors.leftMargin: Util.leftMargin +(m_lineValue*1.5 - m_lineValue*1.5*0.7)/2
                        anchors.verticalCenter: parent.verticalCenter
                        sourceSize: Qt.size(m_lineValue*0.35,m_lineValue*0.35)
                        source: "qrc:/image/personpage/wo_help.png"
                    }
                    AText {
                        anchors.left: question.right
                        anchors.leftMargin: m_lineValue*0.2
                        anchors.verticalCenter: parent.verticalCenter
                        text: qsTr("问题反馈")
                        font.pointSize: Style.fontlittlcontent
                        color:Style.fonttilteColor
                    }
                    Image {
                        anchors.right: parent.right
                        anchors.rightMargin: m_lineValue*0.2
                        anchors.verticalCenter: parent.verticalCenter
                        sourceSize: Qt.size(m_lineValue*0.3,m_lineValue*0.3)
                        source: "qrc:/image/arrow.png"
                    }
                    onMouseclickSignal: {
                        Util.pushView(component,m_objects,"qrc:/qml/form/personpage/ProblemFeedback.qml",m_root_id,{})
                    }

                    SplitLine
                    {
                        width: m_root_id.width - Util.leftMargin - (m_lineValue*1.5 - m_lineValue*1.5*0.7)/2
                        anchors {
                            bottom: parent.bottom
                            right: parent.right;
                            left: parent.left
                            leftMargin: m_lineValue*0.3
                        }
                    }
                }
                PushButton {
                    anchors.top:comproblem.bottom
                    width: parent.width
                    Image {
                        id: exit
                        anchors.left: parent.left
                        anchors.leftMargin:  Util.leftMargin +(m_lineValue*1.5 - m_lineValue*1.5*0.7)/2
                        anchors.verticalCenter: parent.verticalCenter
                        sourceSize: Qt.size(m_lineValue*0.35,m_lineValue*0.35)
                        source: "qrc:/image/personpage/wo_exit.png"
                    }

                    AText {
                        anchors.left: exit.right
                        anchors.leftMargin: m_lineValue*0.2
                        anchors.verticalCenter: parent.verticalCenter
                        text: qsTr("退出")
                        font.pointSize: Style.fontlittlcontent
                        color:Style.fonttilteColor
                    }
                    SplitLine {
                        anchors {
                            bottom: parent.bottom
                            right: parent.right;
                            left: parent.left
                            leftMargin: m_lineValue*0.3
                        }
                    }
                    onClickSignal: {

                        var str = "确定退出当前账号"
                        var temp = Util.showPopWin(m_root_id,"qrc:/qml/form/dialog/Dialog_sure_and_cancel_warning.qml",str,function (retValue){});
                        temp.sure_cancel_signal.disconnect(onSure_cancel_signal)
                        temp.sure_cancel_signal.connect(onSure_cancel_signal)
                    }
                }
            }
        }
    }
    function onSure_cancel_signal(value)
    {
        if(value)
            quitsignal();
    }
}
